package com.wanxi.controller;

import com.wanxi.model.NewsclassificationModel;
import com.wanxi.model.ResultModel;
import com.wanxi.service.NewsclassificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 杨金乾
 */
@Controller
@CrossOrigin(origins = "*")
public class NewsclassificationController{
    @Autowired
    private NewsclassificationService newsclassificationService;

    @Autowired
    SendMessageController sendMessageController;
    private String table="新闻分类";
    @RequestMapping("/back/newsclassification/add")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')")

    protected ResultModel newsclassificationAdd(NewsclassificationModel model){
        ResultModel resultModel =newsclassificationService.add(model);
        sendMessageController.addUserMessages(table);
//        6.返回给前端
        return resultModel;
    }

    @RequestMapping("/back/newsclassification/delete")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')")
    protected ResultModel newsclassificationDelete(NewsclassificationModel model){
        ResultModel resultModel =newsclassificationService.delete(model);
        sendMessageController.deleteUserMessages(table);
//        6.返回给前端
        return resultModel;
    }

    @RequestMapping("/back/newsclassification/findAll")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')or hasAuthority('unaccessible')")
    protected ResultModel newsclassificationFindAll(NewsclassificationModel model){
        ResultModel resultModel =newsclassificationService.findAll(model);
        sendMessageController.findAllUserMessages(table);
//        6.返回给前端
        return resultModel;
    }

    @RequestMapping("/back/newsclassification/findById")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')or hasAuthority('unaccessible')")
    protected ResultModel newsclassificationFindById(NewsclassificationModel model){
        ResultModel resultModel =newsclassificationService.findById(model);
        sendMessageController.findByIdUserMessages(table);
//        6.返回给前端
        return resultModel;
    }

    @RequestMapping("/back/newsclassification/isShow")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')or hasAuthority('unaccessible')")
    protected ResultModel newsclassificationUpdateIsShow(NewsclassificationModel model){
        ResultModel resultModel =newsclassificationService.isShow(model);
        sendMessageController.updateIsShowMessages(table);
//        6.返回给前端
        return resultModel;
    }

    @RequestMapping("/back/newsclassification/update")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')")
    protected ResultModel newsclassificationUpdate(NewsclassificationModel model){
        ResultModel resultModel =newsclassificationService.update(model);
        sendMessageController.updateMessages(table);
//        6.返回给前端
        return resultModel;
    }
}
